-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a helper method for reading/writing memory #123
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Fiddle::Pointer[value]
and Fiddle::Pointer[address, length]
may be confused.
How about Fiddle::Pointer.read
/Fiddle::Pointer.write
(like IO.read
/IO.write
) instead?
That sounds good to me. I wish we could use |
This commit adds two new methods, `Fiddle::Pointer.read` and `Fiddle::Pointer.write`. Both methods take an address, and will read or write bytes at that address respectively. For example we can read from an address without making a Pointer object: ```ruby Fiddle::Pointer.read(address, 5) # read 5 bytes ``` We can also write to an address without allocating a Pointer object: ```ruby Fiddle::Pointer.write(address, "bytes") # write 5 bytes ``` This allows us to read / write memory at arbitrary addresses without instantiating a new `Fiddle::Pointer` object. Co-Authored-By: Sutou Kouhei <[email protected]>
e66658c
to
687f214
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
Co-authored-by: Sutou Kouhei <[email protected]>
Co-authored-by: Sutou Kouhei <[email protected]>
(ruby/fiddle#123) This commit adds two new methods, `Fiddle::Pointer.read` and `Fiddle::Pointer.write`. Both methods take an address, and will read or write bytes at that address respectively. For example we can read from an address without making a Pointer object: ```ruby Fiddle::Pointer.read(address, 5) # read 5 bytes ``` We can also write to an address without allocating a Pointer object: ```ruby Fiddle::Pointer.write(address, "bytes") # write 5 bytes ``` This allows us to read / write memory at arbitrary addresses without instantiating a new `Fiddle::Pointer` object. Examples where this API would be useful [1](https://github.com/tenderlove/tenderjit/blob/f03481d28bff4d248746e596929b0841de65f181/lib/tenderjit/fiddle_hacks.rb#L26-L28) [2](https://github.com/tenderlove/ruby/blob/77c8daa2d40dd58eeb3785ce17dea2ee38f308d1/lib/ruby_vm/rjit/c_pointer.rb#L193) [3](https://github.com/tenderlove/ruby/blob/77c8daa2d40dd58eeb3785ce17dea2ee38f308d1/lib/ruby_vm/rjit/c_pointer.rb#L284) I also added a writer method for the same reasons as the reader. --------- ruby/fiddle@04238cefed Co-authored-by: Sutou Kouhei <[email protected]>
This commit adds two new methods,
Fiddle::Pointer.read
andFiddle::Pointer.write
. Both methods take an address, and will read or write bytes at that address respectively.For example we can read from an address without making a Pointer object:
We can also write to an address without allocating a Pointer object:
This allows us to read / write memory at arbitrary addresses without instantiating a new
Fiddle::Pointer
object.Examples where this API would be useful 1 2 3
I also added a writer method for the same reasons as the reader.